#include "mylabel.h"
#include<QLabel>
#include<QDebug>
#include<QMouseEvent>
#include"painter.h"

MyLabel::MyLabel(QWidget *parent):QLabel(parent)
{
    isPaint=false;
}

void MyLabel::SetisPaint(bool press,Painter* p,Image* im,Image** ori){
    isPaint=press;
    img=im;
    origin = ori;
    paint =p;
}

void MyLabel::mousePressEvent(QMouseEvent *ev){
    if(!isPaint){
        return;
    }
    paint->MousePress(ev);
//    qDebug()<<"press";
//    qDebug()<<"x="<<ev->pos().x();
//    qDebug()<<"y="<<ev->pos().y();

}

void MyLabel::mouseMoveEvent(QMouseEvent *ev){
    if(!isPaint){
        return;
    }
    paint->MouseMove(ev);
    paint->PaintLine(img);
    img->ShowImage(this);
    delete origin[1];
    origin[1] =new Image(*img);
//    qDebug()<<"move";
}

void MyLabel::mouseReleaseEvent(QMouseEvent *ev){
    if(!isPaint){
        return;
    }
    paint->MouseRelease(ev);
}
